/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-17 11:12:21
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-17 16:21:38
 */

import 'package:flutter_data_center/model/common/menu_model.dart';
import 'package:flutter_data_center/model/door/door_model.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class DoorController extends GetxController {
  int _total = 0;
  int get total => _total;
  // 门禁列表
  List<DoorModel> _doorList = [];
  List get doorList => _doorList;
  void getDoors() async {
    _doorList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.doorList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _total = data['total'];
      for (var item in data['rows']) {
        _doorList.add(DoorModel.fromJson((item)));
      }
      update();
    }
  }

  // 门禁人员列表
  List<DoorPeopleModel> _peopleList = [];
  List get peopleList => _peopleList;
  void getPeople() async {
    _peopleList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.doorPeopleList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _peopleList.add(DoorPeopleModel.fromJson((item)));
      }
      update();
    }
  }

  int _inCount = 0;
  int get inCount => _inCount;
  int _outCount = 0;
  int get outCount => _outCount;
  void getDoorStatistics() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.doorStatistics,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _inCount = data['in'];
      _outCount = data['out'];
      update();
    }
  }

  List<MenuModel> _menus = [
    MenuModel("进入", "in"),
    MenuModel("离开", "out"),
    MenuModel("访客", "visitor"),
  ];
  List<MenuModel> get menus => _menus;
}
